﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Baosight.ZNH.ZMCommon;
using System.Windows.Controls.Data;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCB.UI.PopWindows;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Telerik.Windows.Controls;
using Baosight.Platform.Core.ServiceModel;
using Baosight.Platform.Core.UI.Controls;
using System.Collections.ObjectModel;
using GanttView.Charts.Common.Interface;
using GanttView.Charts.Common.Instance;
using GanttView.Charts.Enum;
using GanttView.Charts.Common.ItemClass;
using GanttView.Charts.Common;
using GanttView.Charts;
using System.Text.RegularExpressions;

namespace Baosight.ZNH.ZMCB.UI
{
    public partial class ZMCB21 : EFViewCmes
    {
        List<string> list = new List<string>();
        private static string uniqueIdPath = "fdKeyId", taskNamePath = "fdPlace", startDatePath = "fdBeginDate", endDatePath = "fdEndDate", percentCompletePath = "fdComPercent";
        public ZMCB21()
        {
            InitializeComponent();
            this.Gantt.Loaded += new RoutedEventHandler(Gantt_Loaded);
            this.RESULT.LayoutUpdated += new EventHandler(RESULT_LayoutUpdated);
            for (int i = 0; i < 6; i++)
            {
                list.Add("zhangsan" + i.ToString());
            }
            MyFeatures.ItemsSource = list;
        }

        #region 事件回调
        /// <summary>
        /// 初次进入控制按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RESULT_LayoutUpdated(object sender, EventArgs e)
        {
            if (this.status.Value == null)
                return;

            ControlButton(this.status.Value.ToString());
        }

        /// <summary>
        /// 加载Gantt图的数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Gantt_Loaded(object sender, RoutedEventArgs e)
        {
            this.Gantt.TreeGrid.PreparingCellForEdit += new EventHandler<DataGridPreparingCellForEditEventArgs>(TreeGrid_PreparingCellForEdit);
            this.Gantt.Update(this.Gantt.StartDate);
            UpdateGanttData();
        }


        /// <summary>
        /// 在编辑紧前任务前准备block
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TreeGrid_PreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e)
        {
            if ("紧前任务".Equals(e.Column.Header))
            {
                this.EIDataContext.GetBlock("cmes.cb.frontPlaces").Rows.RemoveAll();
                ObservableCollection<ITaskDescriptor> tasks = this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>;
                foreach (ITaskDescriptor task in tasks)
                {
                    if (!task.Equals((e.Row.DataContext as TaskEntryLayoutItem).Data))
                    {
                        EIRow row = new EIRow();
                        row["fdPlace"] = task.TaskName;
                        row["fdPlaceId"] = task.ExtendAttributes["fdPlaceId"];
                        this.EIDataContext.GetBlock("cmes.cb.frontPlaces").AddRow(row);
                    }
                }
                EIRow row0 = new EIRow();
                row0["fdPlace"] = "";
                row0["fdPlaceId"] = "";
                this.EIDataContext.GetBlock("cmes.cb.frontPlaces").AddRow(row0);
            }
        }
        #endregion

        /// <summary>5
        /// 初始化
        /// </summary>
        /// <param name="initData"></param>
        public override void Initialize(Baosight.Platform.Core.EIInfo initData)
        {
            //int rowCt = initData.GetBlock("result").GetRowCount();
            //for (int i = 0; i < rowCt; i++)
            //{
            //    list.Add(initData.GetBlock("result").GetRow(i)["fdPlanName"].ToString() + "方案" + (i+1).ToString());
            //}
            //MyFeatures.ItemsSource = list;

            initData.AddBlock(BuildFrontBlock());//获取前置任务下来框

            base.Initialize(initData);
            if (initData.Get("hasSimulate").Equals("0"))
            {
                Shell.LoadView("ZMCB20");
                return;
            }
            else
            {
                UpdateHeaderData(initData);
                ControlButton(initData.Get("fdStatus") as string);

            }
        }


        ///// <summary>
        ///// 下一方案
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //private void next_Click(object sender, RoutedEventArgs e)
        //{
        //    TempHyperlink = sender as HyperlinkButton;
        //    TempHyperlink.IsEnabled = false;

        //    if (ThisValidate())
        //    {
        //        EIInfo info = new EIInfo();
        //        info.Set(EIConstants.ServiceNameKey, "ZMCB20");
        //        info.Set(EIConstants.MethodNameKey, "queryNext");
        //        info.Set("fdKeyId", this.KeyId.Value);
        //        info.SetBlock(StaticTools.GetBlockByTasklist("result", this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>, uniqueIdPath, taskNamePath, startDatePath, endDatePath, percentCompletePath));
        //        this.Submit(info, querySubmitCompleted);
        //        return;
        //    }
        //    TempHyperlink.IsEnabled = true;
        //}

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void add_Click(object sender, RoutedEventArgs e)
        {
            TempButton = sender as Button;
            TempButton.IsEnabled = false;

            //DataGridTemplateColumn col = this.Gantt.TreeGrid.Columns[0] as DataGridTemplateColumn;
            //col.CellEditingTemplate = (DataTemplate)Resources["WorkfaceComboBox"];  

            if (this.Gantt.DataSource == null)
            {
                this.Gantt.DataSource = new ObservableCollection<ITaskDescriptor>();
            }
            ObservableCollection<ITaskDescriptor> tasks = this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>;
            ITaskDescriptor task = BulidNewTask();
            tasks.Add(task);
            this.Gantt.Update();

            TempButton.IsEnabled = true;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void delete_Click(object sender, RoutedEventArgs e)
        {
            TempButton = sender as Button;
            TempButton.IsEnabled = false;

            if (this.Gantt.TreeGrid.SelectedItems[0] != null)
            {
                TaskEntryLayoutItem task = this.Gantt.TreeGrid.SelectedItems[0] as TaskEntryLayoutItem;
                ObservableCollection<ITaskDescriptor> tasks = this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>;
                tasks.Remove(task.Data);
                this.Gantt.Update();
            }
            else
            {
                BaseTools.OpenEFWindowAlert("请选择一条数据进行删除！", null);
            }
            TempButton.IsEnabled = true;
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public new void OnSaveButtonClick(object sender, RoutedEventArgs e)
        {
            TempButton = sender as Button;
            TempButton.IsEnabled = false;

            if (ThisValidate())
            {
                EIInfo info = new EIInfo();
                info.Set(EIConstants.ServiceNameKey, "ZMCB21");
                info.Set(EIConstants.MethodNameKey, "save");
                info.Set("fdKeyId", this.KeyId.Value);
                info.SetBlock(StaticTools.GetBlockByTasklist("result", this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>, uniqueIdPath, taskNamePath, startDatePath, endDatePath, percentCompletePath));
                this.Submit(info, SaveSubmitCompleted);
                return;
            }
            TempButton.IsEnabled = true;
        }

        /// <summary>
        /// 保存后的回调函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveSubmitCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status >= 0)
            {
                BaseTools.OpenEFWindowAlert("保存成功！", null);
            }
            else
            {
                BaseTools.OpenEFWindowAlert("出错：" + e.EIInfo.Msg, null);
            }
            TempButton.IsEnabled = true;
        }

        /// <summary>
        /// 作废
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnInvalidButtonClick(object sender, RoutedEventArgs e)
        {
            TempButton = sender as Button;
            TempButton.IsEnabled = false;
            if (ThisValidate())
            {
                BaseTools.OpenEFWindowConfirm("确定作废该计划方案？", InvalidWindowAlertClosed);
                return;
            }
            TempButton.IsEnabled = true;
        }

        /// <summary>
        /// 作废确认框关闭后
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void InvalidWindowAlertClosed(object sender, WindowClosedEventArgs e)
        {
            if (e.DialogResult == null || !e.DialogResult.Value)
            {
                this.TempButtonOpen(true);//按钮生效
                return;
            }

            EIInfo info = new EIInfo();
            info.Set(EIConstants.ServiceNameKey, "ZMCB21");
            info.Set(EIConstants.MethodNameKey, "invalid");
            info.Set("fdKeyId", this.KeyId.Value);
            info.SetBlock(StaticTools.GetBlockByTasklist("result", this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>, uniqueIdPath, taskNamePath, startDatePath, endDatePath, percentCompletePath));
            this.Submit(info, querySubmitCompleted);
        }

        /// <summary>
        /// 发布
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnPublishButtonClick(object sender, RoutedEventArgs e)
        {
            TempButton = sender as Button;
            TempButton.IsEnabled = false;

            if (ThisValidate())
            {
                BaseTools.OpenEFWindowConfirm("确定发布该计划方案？", PublishWindowAlertClosed);
                return;
            }
            TempButton.IsEnabled = true;
        }

        /// <summary>
        /// 发布确认框关闭后
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PublishWindowAlertClosed(object sender, WindowClosedEventArgs e)
        {
            if (e.DialogResult == null || !e.DialogResult.Value)
            {
                this.TempButtonOpen(true);//按钮生效
                return;
            }

            EIInfo info = new EIInfo();
            info.Set(EIConstants.ServiceNameKey, "ZMCB21");
            info.Set(EIConstants.MethodNameKey, "publish");
            info.Set("fdKeyId", this.KeyId.Value);
            info.SetBlock(StaticTools.GetBlockByTasklist("result", this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>, uniqueIdPath, taskNamePath, startDatePath, endDatePath, percentCompletePath));
            this.Submit(info, publishSubmitCompleted);
        }

        /// <summary>
        /// 回调函数——查询主表数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void publishSubmitCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status >= 0)
            {
                IDictionary<String, String> args = new Dictionary<string, string>();
                args.Add("fdKeyId", this.KeyId.Value.ToString());
                Shell.LoadView("ZMCB20", args);
                //this.EIDataContext.Update(e.EIInfo);
                //UpdateHeaderData(e.EIInfo);
                //UpdateGanttData();
                //ControlButton(e.EIInfo.Get("fdStatus") as string);
            }
            else
            {
                OpenEFWindowAlert("查询出错啦！" + e.EIInfo.Msg, false);
            }

            if (TempButton != null)
                TempButton.IsEnabled = true;
            if (TempHyperlink != null)
                TempHyperlink.IsEnabled = true;
        }

        /// <summary>
        /// 查看计划表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnViewlistButtonClick(object sender, RoutedEventArgs e)
        {
            TempButton = sender as Button;
            TempButton.IsEnabled = false;


            if (ThisValidate())
            {
                EIInfo info = new EIInfo();
                info.Set(EIConstants.ServiceNameKey, "ZMCB21");
                info.Set(EIConstants.MethodNameKey, "viewlist");
                info.Set("fdKeyId", this.KeyId.Value);
                info.Set("fdStatus", this.status.Value);
                info.SetBlock(StaticTools.GetBlockByTasklist("result", this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>, uniqueIdPath, taskNamePath, startDatePath, endDatePath, percentCompletePath));
                this.Submit(info, ViewlistSubmitCompleted);
                return;
            }
            TempButton.IsEnabled = true;
        }

        /// <summary>
        ///按钮查看计划表后的回调函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ViewlistSubmitCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status >= 0)
            {
                S20Viewlist view = new S20Viewlist();
                view.EIDataContext = new Platform.Core.UI.EIDataContext();
                view.EIDataContext.Update(e.EIInfo);

                view.fdKeyId.Value = this.KeyId.Value;

                CmesWindows _popup = new CmesWindows();//构造一个弹出页面
                _popup.WindowStartupLocation = Telerik.Windows.Controls.WindowStartupLocation.CenterOwner;
                _popup.TopOffset = -150;
                _popup.LeftOffset = -80;
                _popup.ResizeMode = ResizeMode.NoResize;//设置不能修改窗口大小
                _popup.Header = view.eTitle;//设置Title
                _popup.Content = view;//让新增页面在弹出窗口显示
                _popup.Closed += new EventHandler<WindowClosedEventArgs>(ViewlistWindow_Closed);
                _popup.ShowDialog();//模态显示弹出窗口
            }
            else
            {
                BaseTools.OpenEFWindowAlert("出错：" + e.EIInfo.Msg, null);
                TempButton.IsEnabled = true;
            }
        }

        /// <summary>
        /// 关闭查看计划表弹出页面后
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ViewlistWindow_Closed(object sender, WindowClosedEventArgs e)
        {
            TempButton.IsEnabled = true;
        }


        /// <summary>
        /// 打印
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnPrintButtonClick(object sender, RoutedEventArgs e)
        {

        }


        /// <summary>
        /// 回调函数——查询主表数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void querySubmitCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status >= 0)
            {
                this.EIDataContext.Update(e.EIInfo);
                UpdateHeaderData(e.EIInfo);
                UpdateGanttData();
                ControlButton(e.EIInfo.Get("fdStatus") as string);
            }
            else
            {
                OpenEFWindowAlert("查询出错啦！" + e.EIInfo.Msg, false);
            }

            if (TempButton != null)
                TempButton.IsEnabled = true;
            if (TempHyperlink != null)
                TempHyperlink.IsEnabled = true;
        }

        #region  下拉框事件
        /// <summary>
        /// 施工部门下拉框
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DepComboBox_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
        {
            EFComboBox box = sender as EFComboBox;
            if (box.SelectedItem != null)
            {
                ITaskDescriptor row = ((box.Parent as DataGridCell).DataContext as TaskEntryLayoutItem).Data;
                row.ExtendAttributes["fdDepartment"] = box.SelectedItem.GetType().GetProperty("orgName").GetValue(box.SelectedItem, null);
            }
        }

        /// <summary>
        /// 工作地点下拉框
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void placeComboBox_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
        {
            EFComboBox box = sender as EFComboBox;
            if (box.SelectedItem != null)
            {
                ITaskDescriptor row = ((box.Parent as DataGridCell).DataContext as TaskEntryLayoutItem).Data;
                //校验重复
                ObservableCollection<ITaskDescriptor> tasks = this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>;
                foreach (ITaskDescriptor task in tasks)
                {
                    if (!task.Equals(row) && task.TaskName.Equals(box.SelectedItem.GetType().GetProperty("fdPlace").GetValue(box.SelectedItem, null)))
                    {
                        BaseTools.OpenEFWindowAlert("工作地点不能重复！", null);
                        box.ClearValue(EFComboBox.SelectedItemProperty);
                        return;
                    }
                }

                //赋值
                row.TaskName = box.SelectedItem.GetType().GetProperty("fdPlace").GetValue(box.SelectedItem, null) as string;
                row.ExtendAttributes["fdSurplus"] = box.SelectedItem.GetType().GetProperty("fdSurplus").GetValue(box.SelectedItem, null);
                row.ExtendAttributes["fdPlan"] = box.SelectedItem.GetType().GetProperty("fdSurplus").GetValue(box.SelectedItem, null);
                row.ExtendAttributes["fdPlaceType"] = box.SelectedItem.GetType().GetProperty("fdPlaceType").GetValue(box.SelectedItem, null);
                row.ExtendAttributes["fdUnit"] = box.SelectedItem.GetType().GetProperty("fdUnit").GetValue(box.SelectedItem, null);
                if ("采面".Equals(box.SelectedItem.GetType().GetProperty("fdPlaceType").GetValue(box.SelectedItem, null)))
                {
                    row.ExtendAttributes["fdLength"] = box.SelectedItem.GetType().GetProperty("fdSurplusLength").GetValue(box.SelectedItem, null);
                    row.ExtendAttributes["fdSurplusLength"] = box.SelectedItem.GetType().GetProperty("fdSurplusLength").GetValue(box.SelectedItem, null);
                    row.ExtendAttributes["fdHeight"] = box.SelectedItem.GetType().GetProperty("fdHeight").GetValue(box.SelectedItem, null);
                    row.ExtendAttributes["fdWidth"] = box.SelectedItem.GetType().GetProperty("fdWidth").GetValue(box.SelectedItem, null);
                    row.ExtendAttributes["fdBulk"] = box.SelectedItem.GetType().GetProperty("fdBulk").GetValue(box.SelectedItem, null);
                    row.ExtendAttributes["fdChance"] = box.SelectedItem.GetType().GetProperty("fdChance").GetValue(box.SelectedItem, null);
                }
            }
        }

        /// <summary>
        /// 校验计划总量
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox tb = sender as TextBox;
            if (!Regex.IsMatch(tb.Text, @"((^\d{0,8}$)|(^\d{0,8}\.\d{0,4}$)|(^0\.\d{0,4}$))"))
            {
                BaseTools.OpenEFWindowAlert("计划总量只能输入整数位不超过8位，小数位不超过4位的数字！", null);
                tb.Text = "";
                return;
            }
        }

        /// <summary>
        /// 紧前任务下拉框
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrontComboBox_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
        {
            EFComboBox box = sender as EFComboBox;
            if (box.SelectedItem != null)
            {
                ITaskDescriptor row = ((box.Parent as DataGridCell).DataContext as TaskEntryLayoutItem).Data;
                row.ExtendAttributes["fdFrontName"] = box.SelectedItem.GetType().GetProperty("fdPlace").GetValue(box.SelectedItem, null);
            }
        }
        #endregion

        #region  私有方法

        /// <summary>
        /// 构建前置任务下拉框
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        private EIBlock BuildFrontBlock()
        {
            EIBlock front = new EIBlock("cmes.cb.frontPlaces");
            EIColumn eiColumn = new EIColumn();
            eiColumn.Name = "fdPlaceId";
            eiColumn.TypeLabel = "C";
            front.AddColumn(eiColumn);

            eiColumn = new EIColumn();
            eiColumn.Name = "fdPlace";
            eiColumn.TypeLabel = "C";
            front.AddColumn(eiColumn);

            return front;
        }

        /// <summary>
        /// 根据不同的主表状态控制按钮是否可用
        /// </summary>
        /// <param name="status"></param>
        private void ControlButton(string status)
        {
            if ("草拟".Equals(status))
            {
                Button btn = this.FindName("SAVE") as Button;
                if (btn != null)
                    btn.IsEnabled = true;
                btn = this.FindName("INVALID") as Button;
                if (btn != null)
                    btn.IsEnabled = true;
                btn = this.FindName("PUBLISH") as Button;
                if (btn != null)
                    btn.IsEnabled = true;
                btn = this.FindName("PRINT") as Button;
                if (btn != null)
                    btn.IsEnabled = true;
                btn = this.FindName("VIEWLIST") as Button;
                if (btn != null)
                    btn.IsEnabled = true;
                this.add.IsEnabled = true;
                this.delete.IsEnabled = true;

            }
            else
            {
                Button btn = this.FindName("SAVE") as Button;
                if (btn != null)
                    btn.IsEnabled = false;
                btn = this.FindName("INVALID") as Button;
                if (btn != null)
                    btn.IsEnabled = false;
                btn = this.FindName("PUBLISH") as Button;
                if (btn != null)
                    btn.IsEnabled = false;
                this.add.IsEnabled = false;
                this.delete.IsEnabled = false;
                if ("无计划".Equals(status))
                {
                    btn = this.FindName("PRINT") as Button;
                    if (btn != null)
                        btn.IsEnabled = false;
                    btn = this.FindName("VIEWLIST") as Button;
                    if (btn != null)
                        btn.IsEnabled = false;
                }
                else
                {
                    btn = this.FindName("PRINT") as Button;
                    if (btn != null)
                        btn.IsEnabled = true;
                    btn = this.FindName("VIEWLIST") as Button;
                    if (btn != null)
                        btn.IsEnabled = true;
                }
            }
            if ("生效".Equals(status))
            {
                Button btn = this.FindName("ADJUST") as Button;
                if (btn != null)
                {
                    btn.IsEnabled = true;
                }
            }
            else
            {
                Button btn = this.FindName("ADJUST") as Button;
                if (btn != null)
                {
                    btn.IsEnabled = false;
                }
            }
        }

        /// <summary>
        /// 更新主表页面数据
        /// </summary>
        /// <param name="info"></param>
        private void UpdateHeaderData(EIInfo info)
        {
            //this.title.Text = info.Get("fdPlanName") as string;
            //this.status.Text = info.Get("fdStatus") as string;

            //if ("1".Equals(info.Get("hasPrevious")))
            //    this.previous.Visibility = Visibility.Visible;
            //else
            //    this.previous.Visibility = Visibility.Collapsed;

            //if ("1".Equals(info.Get("hasNext")))
            //    this.next.Visibility = Visibility.Visible;
            //else
            //    this.next.Visibility = Visibility.Collapsed;
        }

        /// <summary>
        /// 更新Gantt图页面数据
        /// </summary>
        private void UpdateGanttData()
        {
            if (this.EIDataContext.ContainsBlockName("result"))
            {
                this.Gantt.DataSource = GanttView.Charts.StaticTools.GetTasklistByBlock(this.EIDataContext.GetBlock("result"), uniqueIdPath, taskNamePath, startDatePath, endDatePath, percentCompletePath);
                this.Gantt.Update();
            }
        }

        /// <summary>
        /// 校验空值
        /// </summary>
        /// <returns></returns>
        private bool ThisValidate()
        {
            ObservableCollection<ITaskDescriptor> tasks = this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>;
            string msg = "";
            for (int i = 0; i < tasks.Count; i++)
            {
                msg += "第" + (i + 1) + "行";
                if (String.IsNullOrEmpty(tasks[i].TaskName))
                {
                    msg += "工作地点不能为空！";
                }
                if ("".Equals(tasks[i].ExtendAttributes["fdDepartment"]))
                {
                    msg += "施工部门不能为空！";
                }
                if ("".Equals(tasks[i].ExtendAttributes["fdPlan"]))
                {
                    msg += "计划总量不能为空！";
                }
                if ("".Equals(tasks[i].ExtendAttributes["fdUnit"]))
                {
                    msg += "单位不能为空！";
                }
                if (default(DateTime).Equals(tasks[i].StartDate))
                {
                    msg += "开始日期不能为空！";
                }
                if (default(DateTime).Equals(tasks[i].EndDate))
                {
                    msg += "结束日期不能为空！";
                }
                if (msg.Substring(msg.Length - 3).Equals("第" + (i + 1) + "行"))
                {
                    msg = msg.Substring(0, msg.Length - 3);
                }
            }
            if (!msg.Equals(""))
            {
                BaseTools.OpenEFWindowAlert(msg, null);
                return false;
            }
            return true;
        }

        /// <summary>
        /// 创建新的任务对象
        /// </summary>
        /// <param name="uintValue"></param>
        /// <param name="placeType"></param>
        /// <returns></returns>
        private ITaskDescriptor BulidNewTask()
        {
            ITaskDescriptor task = new SimpleTaskDescriptor();
            task.TaskType = TaskType.ResourceTask;
            task.ExtendAttributes = new DependencyDictionary<string, object>();
            foreach (string key in this.EIDataContext.GetBlock("result").Columns.Keys)
            {
                if (!key.Equals(uniqueIdPath) && !key.Equals(taskNamePath) && !key.Equals(startDatePath) && !key.Equals(endDatePath) && !key.Equals(percentCompletePath))
                {
                    task.ExtendAttributes[this.EIDataContext.GetBlock("result").Columns[key].Name] = "";
                }
            }
            task.ExtendAttributes["fdForeignKey"] = this.KeyId.Value;
            return task;
        }

        #endregion

        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {

            string planName = (sender as RadioButton).Content.ToString();

            EIInfo info = new EIInfo();
            info.Set(EIConstants.ServiceNameKey, "ZMCB21");
            info.Set(EIConstants.MethodNameKey, "queryDetails");
            info.Set("fdPlanName", planName);
            //info.Set("fdKeyId", this.KeyId.Value);
            //info.Set("fdStatus", this.status.Value);
            this.Submit(info, detailsSubmitCompleted);
        }

        /// <summary>
        /// 回调函数——查询主表数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void detailsSubmitCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status >= 0)
            {
                this.EIDataContext.Update(e.EIInfo);
                //UpdateHeaderData(e.EIInfo);
                UpdateGanttData();
                ControlButton(e.EIInfo.Get("fdStatus") as string);
            }
            else
            {
                OpenEFWindowAlert("查询出错啦！" + e.EIInfo.Msg, false);
            }

        }
    }
}
